local sk__mojian = fk.CreateSkill {

  name = "sk__mojian",

  tags = { Skill.Compulsory, },

}



sk__mojian:addEffect(fk.EventPhaseStart, {
  name = "sk__mojian",
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if target == player then
      if player.phase == Player.Start then
        return player:hasSkill(sk__mojian.name) and player:canUse(Fk:cloneCard("archery_attack"))
      elseif player.phase == Player.Finish then
        return player:getMark("sk__mojian-turn") > 0 and player:canUse(Fk:cloneCard("archery_attack")) and not player.dead
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local card = Fk:cloneCard("archery_attack")
    card.skillName = sk__mojian.name
    local use = {
      from = player,
      card = card,
    }
    room:useCard(use)
    if player.phase == Player.Start and use.extra_data and use.extra_data.sk__mojian and not player.dead then
      room:setPlayerMark(player, "sk__mojian-turn", 1)
    end
  end,
})
sk__mojian:addEffect(fk.CardRespondFinished, {
  can_refresh = function (self, event, target, player, data)
    return target == player and data.card.trueName == "jink" and data.responseToEvent and data.responseToEvent.card and
      table.contains(data.responseToEvent.card.skillNames, sk__mojian.name)
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    local e = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
    if e then
      local use = e.data
      if table.contains(use.card.skillNames, sk__mojian.name) then
        use.extra_data = use.extra_data or {}
        use.extra_data.sk__mojian = true
      end
    end
  end,
})

return sk__mojian